package fr.uhp.wiki;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.*;

import org.hibernate.annotations.CollectionOfElements;

@Entity
public class Article implements java.io.Serializable {

	private static final long serialVersionUID = 6175915826419106188L;
	private int idArticle;
	private String title;
	private String content;
	private Map<Date,String> versions;
	
	public Article() {
		super();
		versions = new HashMap<Date, String>();
	}
	
	@Id
	@Column(name = "id", unique = true, nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getIdArticle() {
		return idArticle;
	}

	public void setIdArticle(int idArticle) {
		this.idArticle = idArticle;
	}
	
	@Column(name = "title", nullable = false, length = 10)
	public String getTitle() {
		return title;
	}
	
	public void setTitle(String title) {
		this.title = title;
	}
	
	@Column(name = "content", nullable = false, length = 10)
	public String getContent() {
		return content;
	}
	
	public void setContent(String content) {
		this.content = content;
	}
	
//	@CollectionOfElements(targetElement=java.util.Date.class,fetch=FetchType.EAGER)
//	@JoinTable(name="versions_table", joinColumns=@JoinColumn(name="id"))
//	@org.hibernate.annotations.MapKey(columns=@Column(name="version_content"))
//	@Column(name="article_version")
//	@MapKey(name="date")
	@CollectionOfElements
	public Map<Date, String> getVersions() {
		return versions;
	}
	
	public void setVersions(HashMap<Date, String> versions) {
		this.versions = versions;
	}
}
